Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reworked parsing & conversion #71

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

barucden
Copy link
Collaborator

@barucden barucden commented Oct 16, 2024

This is a bigger PR. I am sorry. It started off with parsing, but then got into printing too. If it's too large to review, I will try to split it into multiple PRs.

Summary:

  • Parsing implemented according to https://speleotrove.com/decimal/daconvs.html#refnumsyn
  • tryparse is now available too
  • Printing implemented via scientific notation described at https://speleotrove.com/decimal/daconvs.html#reftostr
  • Removed number(::Decimal): the function was type-unstable, returning Float64 or Int64 depending on the value of the Decimal. The user has the option to call Float64(::Decimal) or Int64(::Decimal) based on their need.
  • Removed decimal(x): The user can use Decimal(x) if x is a number, and parse(Decimal, x) or (newly) dec"123.456" if x is a string.

Fixes #20:

julia> parse(Decimal, "3.2.1")
ERROR: ArgumentError: Invalid decimal: 3.2.1

Fixes #45:

# Again, decimal(::String) removed, but using parse/dec_str:
julia> parse(Decimal, "1.23456789e-13")
1.23456789E-13

julia> parse(Decimal, "1.23456789e-14")
1.23456789E-14

julia> parse(Decimal, "1.23456789e-15")
1.23456789E-15

julia> parse(Decimal, "1.23456789e-21")
1.23456789E-21

Fixes #53:

julia> x = 1.2345678e6
1.2345678e6

julia> Decimal(x)
1234567.8

Closes #21
Closes #24
Closes #55

Copy link

codecov bot commented Oct 16, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 97.81%. Comparing base (db600fe) to head (b2b8412).

Additional details and impacted files
@@            Coverage Diff             @@
##           master      #71      +/-   ##
==========================================
+ Coverage   97.59%   97.81%   +0.22%     
==========================================
  Files           8       10       +2     
  Lines         166      183      +17     
==========================================
+ Hits          162      179      +17     
  Misses          4        4              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@barucden barucden marked this pull request as ready for review October 16, 2024 13:49
@barucden barucden marked this pull request as draft October 17, 2024 10:37
@barucden barucden marked this pull request as ready for review October 17, 2024 10:54
@barucden barucden mentioned this pull request Oct 17, 2024
@barucden
Copy link
Collaborator Author

I think this falls into the category of major changes, @ViralBShah. It removes functions (without removing features though!).

@ViralBShah
Copy link
Member

@oscardssmith Any suggestions on reviewers? @barucden Great contributions, and I suggest give this a few days for folks to chime in. At that point, please merge, and you seem to have already added tests.

@barucden barucden mentioned this pull request Oct 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants